package com.tping.redis;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

public class TestMain {


    public static void main(String[] args){

        /**
         * 手写Redis过期策略算法
         *
         */
        LFU<Integer, String> lfu = new LFU<Integer, String>(4);

        lfu.put(1, "1");
        lfu.put(2, "2");
        lfu.put(3, "3");
        lfu.put(4, "4");

        lfu.get(2);
        lfu.get(2);
        lfu.get(4);
        lfu.put(5, "5");

        Map<Integer, LFU.Node> caches = lfu.getCaches();

        for (Map.Entry<Integer, LFU.Node> entry : caches.entrySet() ){
            System.out.println(entry.getValue());
        }

        System.out.println("=============================================");
        LRU<Integer, String> lru = new LRU<Integer, String>(4);

        lru.put(1, "A");
        lru.put(2, "B");
        lru.put(3, "C");
        lru.put(4, "D");

        lru.get(2);
        lru.get(2);
        lru.get(4);
        lru.put(5, "E");
        Map<Integer, LRU.Node> lruCaches = lru.getCaches();
        for (Map.Entry<Integer, LRU.Node> entry : lruCaches.entrySet() ){
            System.out.println(entry.getValue());
        }


        ThreadLocal<String> threadLocal = new ThreadLocal<>();
        threadLocal.set("999");
        System.out.println("threadLocal: " + threadLocal.get());
        System.out.println("threadLocal: " + threadLocal.get());

        ThreadLocal<String> threadLocal2 = new ThreadLocal<>();
        threadLocal2.set("888");
        System.out.println("threadLocal: " + threadLocal2.get());


    }

    public synchronized void add(){
        ConcurrentHashMap hashMap = new ConcurrentHashMap();

        ReentrantLock lock = new ReentrantLock();

        lock.lock();
    }

}
